package controller;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;

import javax.swing.JFileChooser;

import model.Image;
import view.Thumbnail;

public class ThumbnailController {
	
	private Thumbnail thumbnail;
	private Image image;
	
	public ThumbnailController(Thumbnail thumbnail, Image image) {
		this.thumbnail = thumbnail;
		this.image = image;
		
		this.thumbnail.addChangeImageListener(new ImageMouseListener());
	}
	
	class ImageMouseListener implements MouseListener {

		@Override
		public void mouseClicked(MouseEvent event) {
			JFileChooser chooser = new JFileChooser();
			int validValue = chooser.showOpenDialog(thumbnail);
			if(validValue == JFileChooser.APPROVE_OPTION) {
				try {
					image.setImagePath(chooser.getSelectedFile().getPath());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			
		}

		@Override
		public void mouseExited(MouseEvent e) {
			
		}

		@Override
		public void mousePressed(MouseEvent e) {
			
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			
		}
		
	}
	
	
}